代码/字面量创建.html
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        // * 套路: 自定义构造函数, 属性在函数中初始化, 方法添加到原型上
        // \* 适用场景: 需要创建多个类型确定的对象,且避免了相同方法占用内存
        // \* 问题: 语法比较繁琐
        function Person(name, age) {
            this.name = name
            this.age = age
            // this.list = function () { console.log(this.name)}
        }
        // // console.log(Person.prototype)
        Person.prototype.list = function () {
            console.log(this.name)
        }

        let o1 = new Person('李四', 20)
        let o2 = new Person('王五', 30)
        console.log(o1, o2)
        o1.list()





    </script>
</body>

</html>